/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.log.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.common.utils.CommonUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.log.excel.IntegralTrainingLogExcel;
import org.springblade.modules.log.excel.IntegralTrainingLogImporter;
import org.springblade.modules.log.service.IIntegralLogService;
import org.springblade.modules.log.service.IIntegralTrainingLogService;
import org.springblade.modules.log.service.IIntegralYearLogService;
import org.springblade.modules.personal.service.IUserBaseService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.log.entity.IntegralTrainingEntity;
import org.springblade.modules.log.vo.IntegralTrainingVO;
import org.springblade.modules.log.wrapper.IntegralTrainingWrapper;
import org.springblade.modules.log.service.IIntegralTrainingService;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.Map;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

/**
 * 教师培训记录台账 控制器
 *
 * @author junxin
 * @since 2023-05-24
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-integralTraining/integralTraining")
@Api(value = "教师培训记录台账", tags = "教师培训记录台账接口")
public class IntegralTrainingController extends BladeController {

	private final IIntegralTrainingService integralTrainingService;
	private final IIntegralTrainingLogService integralTrainingLogService;
	private final IIntegralLogService integralLogService;

	/**
	 * 教师培训记录台账 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入integralTraining")
	public R<IntegralTrainingVO> detail(IntegralTrainingEntity integralTraining) {
		IntegralTrainingEntity detail = integralTrainingService.getOne(Condition.getQueryWrapper(integralTraining));
		return R.data(IntegralTrainingWrapper.build().entityVO(detail));
	}
	/**
	 * 教师培训记录台账 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入integralTraining")
	public R<IPage<IntegralTrainingVO>> list(@ApiIgnore @RequestParam Map<String, Object> integralTraining, Query query) {
		IPage<IntegralTrainingEntity> pages = integralTrainingService.page(Condition.getPage(query), Condition.getQueryWrapper(integralTraining, IntegralTrainingEntity.class));
		return R.data(IntegralTrainingWrapper.build().pageVO(pages));
	}

	/**
	 * 教师培训记录台账 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入integralTraining")
	public R save(@Valid @RequestBody IntegralTrainingEntity integralTraining) {
		return R.status(integralTrainingService.save(integralTraining));
	}

	/**
	 * 教师培训记录台账 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入integralTraining")
	public R update(@Valid @RequestBody IntegralTrainingEntity integralTraining) {
		return R.status(integralTrainingService.updateById(integralTraining));
	}

	/**
	 * 教师培训记录台账 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(integralTrainingService.deleteLogic(Func.toLongList(ids)));
	}


	@PostMapping("import-training-integral")
	@ApiOperationSupport(order = 13)
	@ApiOperation(value = "导入教师培训台账记录", notes = "传入excel")
	@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
	public R importQuestionBank(MultipartFile file) {
		IntegralTrainingLogImporter integralTrainingLogImporter = new IntegralTrainingLogImporter(integralTrainingLogService,integralTrainingService,integralLogService);
		ExcelUtil.save(file, integralTrainingLogImporter, IntegralTrainingLogExcel.class);
		return R.success("操作成功");
	}
	/**
	 * 导出模板
	 */
	@GetMapping("export-training-integral-template")
	@ApiOperationSupport(order = 14)
	@ApiOperation(value = "导出模板")
	public void exportUser(HttpServletResponse response) {
		List<IntegralTrainingLogExcel> list = new ArrayList<>();
		ExcelUtil.export(response, "教师培训台账记录数据模板", "教师培训台账记录数据表", list, IntegralTrainingLogExcel.class);
	}


}
